package com.xxd.spring.boot.demo.zhuhongbing.controller;

import com.xxd.spring.boot.demo.zhuhongbing.util.Result;
import com.xxd.spring.boot.demo.zhuhongbing.constant.ConstantDate;
import com.xxd.spring.boot.demo.zhuhongbing.entity.User;
import com.xxd.spring.boot.demo.zhuhongbing.exception.MyException;
import com.xxd.spring.boot.demo.zhuhongbing.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.UUID;

@RestController
@RequestMapping("/user")
public class UserController {
    @Autowired
    private UserService userService;
    @RequestMapping("/regsit")
    public Result regsit(@RequestBody User user) throws MyException {
        userService.regsit(user);
        return new Result().success();
    }
    @RequestMapping("/login")
    public Result login(@RequestBody User user) throws MyException {
        User dbUser=userService.login(user.getUsername(),user.getPassword());
         String  uuid=UUID.randomUUID().toString();
        ConstantDate.userMap.put(uuid,dbUser);
        return new Result().success().setData(uuid);
    }
}
